package com.example.exercise.common.filter;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpFilter;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * xss攻击过滤
 */
@Component
public class XssFilter extends HttpFilter {
    private FilterConfig fc = null;
    public void destroy() {
        fc = null;
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc) throws IOException, ServletException {
        fc.doFilter(new XssHttpServletRequestWrapper((HttpServletRequest)req), resp);
    }

    public void init(FilterConfig fc) {
        this.fc = fc;
    }
}
